package com.gduf.bbl.controller;

import java.io.IOException;
import java.util.Arrays;
import java.util.Map;
import java.util.UUID;


import com.gduf.bbl.common.utils.ImgUtil;
import com.gduf.bbl.common.utils.JesyFileUpload;
import com.gduf.bbl.common.utils.PageUtils;
import com.gduf.bbl.common.utils.R;
import com.gduf.bbl.entity.UserinfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.gduf.bbl.entity.UserinfoEntity;
import com.gduf.bbl.service.UserinfoService;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;



/**
 * 
 *
 * @author xqw
 * @email 2041411595@qq.com
 * @date 2024-02-29 20:38:49
 */
@RestController
@RequestMapping("bbl/userinfo")
@CrossOrigin(allowCredentials = "true")
@Api(tags = "申请配送员管理")
public class UserinfoController {
    @Autowired
    private UserinfoService userinfoService;



    @PostMapping("/sq")
    @ApiOperation("提交申请")
    @ApiImplicitParams({
            @ApiImplicitParam(type = "String",name = "name",value = "名字",required = true),
            @ApiImplicitParam(type = "String",name = "formId",value = "学号",required = true),
            @ApiImplicitParam(type = "String",name = "areaId",value = "校区id",required = true),
            @ApiImplicitParam(type = "String",name = "userId",value = "用户id",required = true)
    })
    public R sq(MultipartFile cert,String name,String formId,String areaId,String userId) throws IOException {

        //保存图片
        final String s = ImgUtil.uploadImg(cert);

        return userinfoService.sq(name,formId,s,areaId,userId);
    }

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = userinfoService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		UserinfoEntity userinfo = userinfoService.getById(id);

        return R.ok().put("userinfo", userinfo);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody UserinfoEntity userinfo){
		userinfoService.save(userinfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public R update(@RequestBody UserinfoEntity userinfo){
		userinfoService.updateById(userinfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		userinfoService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
